#Boa:Frame:FAjustes

import wx
import os


def create(parent):
    return FAjustes(parent)

[wxID_FAJUSTES, wxID_FAJUSTESBACERCADE, wxID_FAJUSTESBAPAGAR, 
 wxID_FAJUSTESBLOGO, wxID_FAJUSTESBMENU, wxID_FAJUSTESBREINICIAR, 
] = [wx.NewId() for _init_ctrls in range(6)]

class FAjustes(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FAJUSTES, name=u'FAjustes', parent=prnt,
              pos=wx.Point(504, 167), size=wx.Size(300, 220),
              style=wx.DEFAULT_FRAME_STYLE, title=u'Ajustes')
        self.SetClientSize(wx.Size(300, 220))
        self.Inserta_Foto("imagen/menu_background.png",(0,0))

        ## Logo
        bmpLogo = wx.Image("imagen/ajustes_menu_boton_logo.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.blogo = wx.BitmapButton(self,-1, bmpLogo,pos=wx.Point(20,20),style=wx.NO_BORDER)
        self.Bind(wx.EVT_BUTTON, self.OnBlogoButton, self.blogo)

        ## Reiniciar
        bmpReiniciar = wx.Image("imagen/ajustes_menu_boton_reiniciar.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.breiniciar = wx.BitmapButton(self,-1, bmpReiniciar,pos=wx.Point(20,80),style=wx.NO_BORDER)
        self.Bind(wx.EVT_BUTTON, self.OnBreiniciarButton, self.breiniciar)

        ## Apagar
        bmpApagar = wx.Image("imagen/ajustes_menu_boton_apagar.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.bapagar = wx.BitmapButton(self,-1, bmpApagar,pos=wx.Point(20,140),style=wx.NO_BORDER)
        self.Bind(wx.EVT_BUTTON, self.OnBapagarButton,self.bapagar)

        ## Atras
        bmpAtras = wx.Image("imagen/boton_atras.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.bmenu = wx.BitmapButton(self,-1, bmpAtras,pos=wx.Point(210,20),style=wx.NO_BORDER)
        self.Bind(wx.EVT_BUTTON, self.OnBmenuButton, self.bmenu)

        ## Acerca de
        bmpAcercaDe = wx.Image("imagen/ajustes_menu_boton_acerca_de.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.bacercade = wx.BitmapButton(self,-1, bmpAcercaDe,pos=wx.Point(170,80),style=wx.NO_BORDER)
        self.Bind(wx.EVT_BUTTON, self.OnBacercadeButton, self.bacercade)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnBlogoButton(self, event):
        dlg = wx.FileDialog(self, 'Choose a file', '.', '', '*.jpg*', wx.OPEN)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                filename = dlg.GetPath()
                comando="cp "+filename+" imagen/sistemas.jpg"
                os.system("rm imagen/sistemas.jpg")
                os.system(comando+"")
                
                #self.Editor.LoadFile(filename)
                #self.FileName=filename
                #self.SetTitle(('Calendario de Actividades -%s')%filename)
        finally:
            dlg.Destroy()
        self.Refresh()
        event.Skip()

    def OnBmenuButton(self, event):
        self.Close(True)
        event.Skip()

    def OnBacercadeButton(self, event):
        event.Skip()
        
    def Inserta_Foto(self, imagenName, pos):
        imagen = open(imagenName, 'rb')
        Img = wx.BitmapFromImage(wx.ImageFromStream(imagen))
        wx.StaticBitmap(self, -1, Img, pos)

    def OnBapagarButton(self, event):
      usuario = os.getlogin()
      os.system("sudo shutdown -h now")
      event.Skip()

    def OnBreiniciarButton(self, event):
      usuario = os.getlogin()
      os.system("sudo reboot")
      event.Skip()
